/*
 * @Author: swl
 * @Date: 2023-07-08 08:57:48
 * @LastEditors: swl
 * @LastEditTime: 2023-07-08 11:58:53
 */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MusicplayService } from '../musicplay.service';
//第三方库
import * as Parse from 'parse';
import { query } from '@angular/animations';
import { observable } from 'rxjs';
(Parse as any).serverURL = 'http://metapunk.cn:9999/parse';
Parse.initialize('dev');

@Component({
  selector: 'app-page-like',
  templateUrl: './page-like.component.html',
  styleUrls: ['./page-like.component.scss'],
})
export class PageLikeComponent implements OnInit {
  // like_data: any[] = [];
  like_data:any[] |undefined
  list:String |undefined
  ngOnInit(): void {
    this.showMyLikeList();
  }
  // 展示我的点赞的方法
  async showMyLikeList() {
    const LikeList: any[] = [];
    const query = new Parse.Query('music_day');
    query
      .find()
      .then((results: Parse.Object[]) => {
        // 处理查询结果
        console.log(results);
        results.forEach((object: Parse.Object) => {
          console.log(object.toJSON()); // 在控制台打印每个对象的JSON表示

          const json = object.toJSON();
          console.log(json['music_songname']);
          // console.log(json.music_songname);
          LikeList.push(json);
        });
        // 打印出转换成数组后的列表
        console.log(LikeList);
        // 显示在界面中
        const loader = document.querySelector('.loader') as HTMLDivElement;

        this.like_data = LikeList.map((item) => {
          const { music_songname, music_author, music_cover } = item;
          // console.log(music_songname);
          return {
            music_songname:music_songname,
            music_author:music_author,
            music_cover:music_cover
          };
        });

        // console.log(`${this.like_data}`);
        this.list = `${this.like_data}`
      })
      .catch((error: Parse.Error) => {
        // 处理错误
        console.error('查询错误: ' + error.code + ' ' + error.message);
      });
  }

  article: any = {};
  constructor(private router: Router) {}

  goBack() {
    this.router.navigate(['/daily-push/page-my']);
  }
  goRegister() {
    this.router.navigate(['../daily-push/register']);
  }
}
